package com.drink.yan.web.rest;

import com.drink.yan.intf.entity.YanCommission;
import com.drink.yan.intf.entity.YanCommissionRule;
import com.drink.yan.intf.vo.CommissionSummaryVo;
import com.drink.yan.intf.vo.CommissionUserVo;
import com.drink.yan.intf.vo.CommissionVo;
import com.drink.yan.svc.service.YanCommissionService;
import com.drink.yan.web.rest.req.cmd.CommissionInAccountCmd;
import com.drink.yan.web.rest.req.cmd.CommissionInPayCmd;
import com.drink.yan.web.rest.req.qry.UserCommissionQry;
import com.drink.yan.web.rest.req.qry.PageCommiRuleQry;
import com.drink.yan.web.rest.req.qry.PageCommissionQry;
import com.meta.framework.common.core.controller.BaseController;
import com.meta.framework.common.core.page.TableResponseVo;
import com.meta.framework.core.ResponseVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

/**
 * java类简单作用描述
 *
 * @Title:
 * @Package: com.drink.yan.web.rest.app.
 * @Author: M.simple
 * @Remark: The modified content
 * @CreateDate: 2023/11/23 14:58
 * @Version: v2.0
 */
@RestController
@RequestMapping("/commission")
public class CommissionRest extends BaseController {

    @Resource
    private YanCommissionService yanCommissionService;

    @ApiOperation(value = "我的收益明细总面板", notes = "我的收益明细总面板", tags = {"学生小程序","员工小程序"})
    @GetMapping("/summary")
    public ResponseVo<CommissionSummaryVo> summary(UserCommissionQry userCommissionQry){

            return ResponseVo.success(yanCommissionService.summary(userCommissionQry));
    }

    @ApiOperation(value = "我的收益明细", notes = "我的收益明细", tags = {"学生小程序","员工小程序"})
    @GetMapping("/listCommission")
    public TableResponseVo<CommissionVo> listCommission(UserCommissionQry qry){

        if(Objects.isNull(qry.getOrderByColumn())){
            qry.setOrderByColumn("id");
            qry.setIsAsc("desc");
        }

        startPage();
        List<CommissionVo> list = yanCommissionService.listCommission(qry);
        TableResponseVo responseVoTable = getResponseVoTable(list);
        responseVoTable.setSum(yanCommissionService.sumAmount(qry));
        return responseVoTable;
    }

    @ApiOperation(value = "佣金列表", notes = "佣金列表", tags = {"PC"})
    @GetMapping("/page")
    public TableResponseVo<CommissionVo> pageCommission(PageCommissionQry qry){

        if(Objects.isNull(qry.getOrderByColumn())){
            qry.setOrderByColumn("id");
            qry.setIsAsc("desc");
        }
        startPage();
        List<CommissionVo> list = yanCommissionService.listCommissionVo(qry);
        TableResponseVo responseVoTable = getResponseVoTable(list);
        return responseVoTable;
    }

    @ApiOperation(value = "学生维度佣金列表", notes = "学生维度佣金列表", tags = {"学生小程序"})
    @GetMapping("/listCommissionUser")
    public TableResponseVo<CommissionUserVo> listCommissionUser(UserCommissionQry qry){

        startPage();
        List<CommissionUserVo> list = yanCommissionService.listCommissionUser(qry);
        TableResponseVo responseVoTable = getResponseVoTable(list);
        return responseVoTable;
    }

    @ApiOperation(value = "佣金入账", notes = "佣金入账", tags = {"PC"})
    @PostMapping("/inAccount")
    public ResponseVo<YanCommission> inAccount(@RequestBody CommissionInAccountCmd cmd){

        YanCommission yanCommission = yanCommissionService.inAccount(cmd);
        return ResponseVo.success(yanCommission);
    }

    @ApiOperation(value = "佣金发放", notes = "佣金发放", tags = {"PC"})
    @PostMapping("/inPay")
    public ResponseVo<YanCommission> inPay(@RequestBody CommissionInPayCmd cmd){

        YanCommission yanCommission = yanCommissionService.inPay(cmd);
        return ResponseVo.success(yanCommission);
    }

    @ApiOperation(value = "保存佣金规则", notes = "保存佣金规则", tags = {"PC"})
    @PostMapping("/rule/save")
    public ResponseVo<YanCommissionRule> saveRule(@RequestBody YanCommissionRule cmd){

        YanCommissionRule yanCommission = yanCommissionService.saveRule(cmd);
        return ResponseVo.success(yanCommission);
    }

    @ApiOperation(value = "佣金规则列表", notes = "佣金规则列表", tags = {"PC"})
    @GetMapping("/rule/list")
    public TableResponseVo<List<YanCommissionRule>> listRule(PageCommiRuleQry qry){

        startPage();
        List<YanCommissionRule> list = yanCommissionService.listCommissionRule();
        return getResponseVoTable(list);
    }

}
